﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.IO;
using BingVis.Common;

namespace BingVis.GoogleTransit.Test
{
    /// <summary>
    /// Summary description for TransitPackageLoaderTest
    /// </summary>
    [TestClass]
    public class TransitPackageLoaderTest
    {
        // TODO: Refactor this to be directory independant.
        private static string _testFilePath = @"C:\Projects\mbtafarevis\DataFiles\google_transit";

        private static DirectoryFileLoader fileLoader;
        private static PackageLoader packageLoader;
        private static List<IGTFSFile> files;

        [ClassInitialize]
        public static void With_PackageLoader_Loading_From_TestData_Directory(TestContext tc)
        {
            // Arrange
            fileLoader = new DirectoryFileLoader(_testFilePath);
            packageLoader = new PackageLoader();

            // Assign
            files = packageLoader.ParseFiles(fileLoader);
        }

        public TransitPackageLoaderTest()
        {
            
        }

        [TestMethod]
        public void Should_Load_9_Files_From_TestFiles_Directory()
        {            
            // Assert
            Assert.AreEqual<int>(9, files.Count);
        }

        [TestMethod]
        public void Should_Contain_Agency_Calendar_Calendar_Dates_Frequencies_Routes_Shapes_Stop_Times_Stops_Trips_From_TestFiles_Directory()
        {   
            // Assert            
            Assert.IsTrue(files.Any(x => Path.GetFileName(x.FileName) == "agency.txt"));
            Assert.IsTrue(files.Any(x => Path.GetFileName(x.FileName) == "calendar.txt"));
            Assert.IsTrue(files.Any(x => Path.GetFileName(x.FileName) == "calendar_dates.txt"));
            Assert.IsTrue(files.Any(x => Path.GetFileName(x.FileName) == "frequencies.txt"));
            Assert.IsTrue(files.Any(x => Path.GetFileName(x.FileName) == "routes.txt"));
            Assert.IsTrue(files.Any(x => Path.GetFileName(x.FileName) == "shapes.txt"));
            Assert.IsTrue(files.Any(x => Path.GetFileName(x.FileName) == "stop_times.txt"));
            Assert.IsTrue(files.Any(x => Path.GetFileName(x.FileName) == "stops.txt"));
            Assert.IsTrue(files.Any(x => Path.GetFileName(x.FileName) == "trips.txt"));            
        }
    }
}
